package src.web.servlet;

import src.domain.Account;
import src.service.AccountService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name="web_UsernameExist",urlPatterns = "/web/usernameExist")
public class UsernameExistServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException
    {
        String username=req.getParameter("username");
        AccountService accountService=new AccountService();
        Account account=accountService.getAccountbyUserID(username);
        resp.setContentType("text/plain");
        resp.setHeader("Access-Control-Allow-Origin","*");
        PrintWriter out =resp.getWriter();
        if(account!=null)
        {
            out.print("Exist");
        }
        else {
            out.print("Not Exist");
        }
    }
}
